<template>
	<view>
		<view style="line-height:100rpx;font-size:40rpx;background:#fff;padding:0 30rpx;box-sizing: border-box;font-weight: bold;">
			绑定手机号
		</view>
		<form>
			<view class='addAddress'>
				<view class='list'>
					<view class='item acea-row row-between-wrapper' style="border-top:none;">
						<view class='name'><em style="color:#f00;margin-right:10rpx;"></em>手机号码</view>
						<input type='text' placeholder='请输入手机号码' v-model="bankInfo.mobile"
							placeholder-class='placeholder'></input>
					</view>
					<view class='item acea-row row-between-wrapper' style="position:relative">
						<view class='name'><em style="color:#f00;margin-right:10rpx;">*</em>验证码</view>
						<input type='text' placeholder='请输入验证码' v-model="bankInfo.vcode"
							placeholder-class='placeholder'></input>
						<view class="dxCodeBox" @click="getUpMemberBankSmsCode" v-if="isFirstDxCode">获取验证码</view>	
						<view class="dxCodeBox" style="color:#ccc;" v-else>
							<view v-if="dxCodeTime>0">剩余 {{dxCodeTime}}s</view>
							<view v-else style="color:#f00;" @click="getAgain">再次获取</view>
						</view>
					</view>
				</view>
				<button class='keepBnt bg-color' @click="saveFunc">立即保存</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		shop_ht,
	} from '@/config/app_member.js';
	export default {
		data() {
			return {
				bankInfo:{
					token:"",
					memberCode:"",
					memberType:3,
					mobile:"",
					vcode:"",
					verificationCodeType: 9
				},
				isFirstDxCode:true,
				dxCodeTime:60,
				dxCodeTimeFun:null
			};
		},
		mounted() {
			this.bankInfo.memberCode = uni.getStorageSync('userInfo').memberCode || "";
			this.bankInfo.token=this.$w_md5.hex_md5_32Upper('tlSendVerificationCode'+uni.getStorageSync('userInfo').memberCode);
		},
		methods: {
			getUpMemberBankSmsCode(){
				this.bankInfo.token=this.$w_md5.hex_md5_32Upper('tlSendVerificationCode'+uni.getStorageSync('userInfo').memberCode);
				if(!this.bankInfo.mobile){
					this.$util.Tips({
						title: '手机号不能为空！'
					});
					return;
				}
				uni.request({
					url: shop_ht+'/shop_ht/manage/tlSendVerificationCode.do',
					method: "get",
					data: this.bankInfo,
					success: (res) => {
						if(res.data.status==1){
							this.$util.Tips({
								title: '验证码发送成功'
							});
							this.setdxCodeTime();
						}else if(res.data.status==2){
							this.$util.Tips({
								title: '该短信已经在发送中，请不要重复请求!'
							});
						}else{
							this.$util.Tips({
								title: '验证码发送失败'
							});
						}
					}
				})
			},
			setdxCodeTime(){
				this.isFirstDxCode=false;
				this.dxCodeTimeFun=setInterval(()=>{
					if(this.dxCodeTime>0){
						this.dxCodeTime=this.dxCodeTime-1;
					}else{
						clearInterval(this.dxCodeTimeFun);
					}
					this.$forceUpdate();
				},1000)
			},
			//再次获取
			getAgain(){
				this.dxCodeTime=60;
				this.getUpMemberBankSmsCode();
			},
			saveFunc(){
				let that=this;
				if(!this.bankInfo.mobile){
					this.$util.Tips({
						title: '手机号不能为空！'
					});
					return;
				}
				if(!this.bankInfo.vcode){
					this.$util.Tips({
						title: '验证码不能为空！'
					});
					return;
				}
				this.bankInfo.token=this.$w_md5.hex_md5_32Upper('tlBindPhone'+uni.getStorageSync('userInfo').memberCode);
				uni.request({
					url: shop_ht+'/shop_ht/manage/tlBindPhone.do',
					method: "get",
					data: this.bankInfo,
					success: (res) => {
						if(res.data.status==1){
							that.$util.Tips({
								title: "手机号绑定成功！"
							});
							setTimeout(()=>{
								uni.navigateBack();
								// uni.navigateTo({
								// 	url: "/pages/electronicWallet/bankCardDo/requestBindbankcard"
								// });
							},2000)
						}else{
							that.$util.Tips({
								title: `${res.data.msg}`
							});
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.addAddress .list {
		background-color: #fff;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.addAddress .list .item {
		padding: 30rpx;
		border-top: 1rpx solid #eee;
	}

	.addAddress .list .item .name {
		width: 195rpx;
		font-size: 30rpx;
		color: #333;
	}

	.addAddress .list .item .address {
		// width: 412rpx;
		flex: 1;
		margin-left: 20rpx;
	}

	.addAddress .list .item input {
		width: 400rpx;
		font-size: 30rpx;
		text-align: left;
	}

	.addAddress .list .item .placeholder {
		color: #ccc;
	}

	.addAddress .list .item picker {
		width: 410rpx;
		height: 42rpx;
	}

	.addAddress .list .item picker .picker {
		width: 350rpx;
		font-size: 30rpx;
		text-align: right;
	}

	.addAddress .list .item picker .iconfont {
		font-size: 43rpx;
	}

	.addAddress .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}

	.addAddress .default checkbox {
		margin-right: 15rpx;
	}

	.addAddress .keepBnt {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 50rpx auto;
		font-size: 32rpx;
		color: #fff;
	}

	.addAddress .wechatAddress {
		width: 690rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		margin: 0 auto;
		font-size: 32rpx;
		color: #fe960f;
		border: 1px solid #fe960f;
	}
	.dxCodeBox{
		position:absolute;
		right:10rpx;
		top:30rpx;
		color:#f00;
		font-size:28rpx;
	}
	.messageBox{
		padding:20rpx 30rpx;
		box-sizing: border-box;
		margin-top:20rpx;
	}
</style>
